/**
 * 
 */
package com.huawei.esdk.uc.sametime.services;

import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;

import com.huawei.esdk.uc.jna.UCService;
import com.huawei.esdk.uc.jna.Constants.MemStatusInCall;
import com.huawei.esdk.uc.jna.Constants.UCServiceRetvCode;
import com.huawei.esdk.uc.sametime.models.ParticipantList;
import com.huawei.esdk.uc.sametime.util.ImageFactory;

/**
 * @author y00175154
 * 
 */
public class UCConfService
{

    /**
     * 创建即时会议
     * @param persons
     * @return
     */
    public static boolean createConference(ParticipantList persons)
    {
        // 这里调用UC SDK的创建即时会议的接口，返回true：创建成功；false：创建失败
        boolean result = UCCallService.startCall(persons);
        return result;
    }

    /**
     * 退出即时会议,如果是自己创建的即时会议,则退出时候会结束会议,而不是单单退出
     * @return 是否退出会议
     */
    public static boolean endConference()
    {
        boolean result = UCCallService.endCall();
        return result;
    }

    /**
     * 踢出与会人
     * @param accountType
     * @param ucAccount
     * @return
     */
    public static boolean deleteMemberInConf(int accountType, String ucAccount)
    {
        int ret = UCService.getInstance().UC_SDK_DeleteMemberInCall(
                accountType, ucAccount);
        if (UCServiceRetvCode.UC_SDK_Success == ret)
        {
            return true;
        }
        return false;
    }

    /**
     * 邀请与会人
     * @param accountType
     * @param ucAccount
     * @return
     */
    public static boolean inviteMemberInConf(int accountType, String ucAccount)
    {
        int ret = UCService.getInstance().UC_SDK_InviteMemberInCall(
                accountType, ucAccount);
        if (UCServiceRetvCode.UC_SDK_Success == ret)
        {
            return true;
        }
        return false;
    }

    /**
     * 修改与会人话语权
     * @param accountType
     * @param ucAccount
     * @return
     */
    public static boolean modifyMemberStatusInConf(int operateType, int accountType,
            String ucAccount)
    {
        int ret = UCService.getInstance().UC_SDK_ModifyMemberStatusInCall(
                operateType, accountType, ucAccount);
        if (UCServiceRetvCode.UC_SDK_Success == ret)
        {
            return true;
        }
        return false;
    }

    /**
     * 获取会议状态图标
     * @param status
     * @return
     */
    public static Image getConfStatusImage(int status)
    {
        Image statusImage;
        if (MemStatusInCall.CONF_MEM_INVITING == status)
        { // 正在呼叫某成员 | 新增成员
            statusImage = getImage(ImageFactory.ICON_CALLING);
        }
        else if (MemStatusInCall.CONF_MEM_HANGUP == status
                || MemStatusInCall.CONF_MEM_QUIT == status
                || MemStatusInCall.CONF_MEM_DEL == status)
        { // 某成员挂断 | 成员离开 | 成员被删除
            statusImage = getImage(ImageFactory.ICON_HISTORY_MISSED);
        }
        else if (MemStatusInCall.CONF_MEM_INCONF == status
                || MemStatusInCall.CONF_MEM_UnMute == status
                || MemStatusInCall.CONF_MEM_SPK == status)
        { // 正在会议中  | 成员被取消静音 | 成员在说话
            statusImage = getImage(ImageFactory.ICON_UCSTATUS_BUSY);
        }
        else if (MemStatusInCall.CONF_MEM_MUTE == status)
        { // 成员被静音
            statusImage = getImage(ImageFactory.MUTED);
        }
        else // MemStatusInCall.CONF_MEM_ADD == status
        {
//            statusImage = getImage(ImageFactory.ICON_HISTORY_MISSED);
            statusImage = null;
        }

        return statusImage;
    }

    private static Image getImage(String imgPath)
    {
        return ImageFactory.loadImage(Display.getCurrent(), imgPath);
    }

}
